﻿using BaseData.API.Write.Applications.AppointmentIng.AppointCommand;
using BaseData.API.Write.DTO;
using BaseData.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BaseData.API.Write.Controllers.AppointCon
{
    /// <summary>
    /// API控制器-预约 -写
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class AppointController : ControllerBase
    {
        /// <summary>
        /// 中介者
        /// </summary>
        IMediator mediator;
        /// <summary>
        /// 日志
        /// </summary>
        ILogger<AppointController> logger;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="mediator">中介者</param>
        /// <param name="logger">日志</param>
        public AppointController(IMediator mediator, ILogger<AppointController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }
        /// <summary>
        /// 添加预约信息
        /// </summary>
        /// <param name="add">请求</param>
        /// <returns>返回添加结果</returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddAppoint(AppointAddCommand add)
        {
            try
            {
                logger.LogInformation("添加成功");
                return await mediator.Send(add);
            }
            catch (Exception e)
            {
                logger.LogError("添加失败" + e.Message);
                throw;
            }
        }
        /// <summary>
        /// 预约反填信息
        /// </summary>
        /// <param name="fanCommand"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<AppointDTO>>> AppointFan([FromQuery] AppoinFanCommand fanCommand)
        {
            return mediator.Send(fanCommand);
        }
        /// <summary>
        /// 预约修改状态
        /// </summary>
        /// <param name="state"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AppointState([FromQuery] AppoinStateCommand state)
        {
            return await mediator.Send(state);
        }
    }
}
